<template>
  <div class="package-basic">
    <div class="lockclass">平台资产包信息</div>
    <el-form ref="setting-package-basic-form" :model="assetsForm" :rules="rules" label-width="220px">
      <el-form-item label="资产名称">
        <el-input v-model="assetsForm.name" :disabled="true"/>
      </el-form-item>
      <el-form-item label="是否免费">
        <el-radio-group v-model="assetsForm.beFree" :disabled="true">
          <el-radio label="1">是</el-radio>
          <el-radio label="0">否</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="定价">
        <el-input v-model="assetsForm.originPrice" :disabled="true" placeholder="0.00"/>
      </el-form-item>
      <el-form-item label="优惠价">
        <el-input v-model="assetsForm.discountPrice" :disabled="true" placeholder="0.00"/>
      </el-form-item>
      <el-form-item label="资产包有效期">
        <el-radio-group v-model="assetsForm.validityTimeType" :disabled="true">
          <el-radio label="days">固定天数</el-radio>
          <el-radio label="times">固定日期</el-radio>
          <el-radio label="forever">无限期</el-radio>
        </el-radio-group>
        <p v-if="assetsForm.validityTimeType === 'days'" style="margin:0; color:#8a8a8a;margin-top:10px;" >
          有效天数
          <el-input-number v-model="assetsForm.days" :min="1" :max="100" :disabled="true" style="margin-left:10px;"/>
        </p>
        <p v-if="assetsForm.validityTimeType === 'times'" style="margin:0; color:#8a8a8a;margin-top:10px;">
          有效日期
          <el-date-picker
            v-model="assetsForm.daterange"
            :disabled="true"
            type="daterange"
            range-separator="|"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            style="margin-left:10px;"
          />
        </p>
      </el-form-item>
      <!-- 第二栏 -->
<!--      <div class="setclass">设置信息</div>
      <el-form-item label="定价" prop="oldprice">
        <el-input v-model.number="form.oldprice" placeholder="0.00"/>
      </el-form-item>
      <el-form-item label="优惠价" prop="newprice">
        <el-input v-model.number="form.newprice" placeholder="0.00"/>
      </el-form-item>
      <el-form-item label="会员课程包">
        <el-radio-group v-model="form.vipPackage">
          <el-radio :label="true">加入会员课程包</el-radio>
          <el-radio :label="false">不加入</el-radio>
        </el-radio-group>
        <br>
        <el-radio-group v-if="form.vipPackage === true" v-model="form.vipPackageFree">
          <el-radio label="vipfree">
            vip免费
            <i class="el-icon-edit"/>
          </el-radio>
          <el-radio label="wipfree">
            wip免费
            <i class="el-icon-edit"/>
          </el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="购买基数" prop="cardinal">
        <el-input v-model.number="form.cardinal"/>
      </el-form-item>
      <el-form-item label="是否为推荐课程包">
        <el-radio-group v-model="form.recommand">
          <el-radio :label="true">是</el-radio>
          <el-radio :label="false">否</el-radio>
        </el-radio-group>
      </el-form-item>-->
      <el-form-item>
        <el-button type="primary" @click="nextStep">下一步</el-button>
        <el-button @click="handleCancel">取消</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  components: {
  },
  props: {
    assets: {
      type: Object,
      default() {
        return {}
      }
    }
  },
  data() {
    var oldprice = (rule, value, callback) => {
      if (!Number.isInteger(value)) {
        callback(new Error('请填入数字'))
      } else {
        if (value < this.form.original) {
          callback(new Error('不能少于平台价格'))
        } else {
          callback()
        }
      }
    }
    var newprice = (rule, value, callback) => {
      if (!Number.isInteger(value)) {
        callback(new Error('请填入数字'))
      } else {
        if (value < this.form.discount) {
          callback(new Error('不能少于平台优惠价'))
        } else {
          callback()
        }
      }
    }
    return {
      form: {
        packageName: '',
        original: '500',
        oldprice: null,
        newprice: null,
        discount: 400,
        free: false,
        until: 1,
        day: 1,
        date: [],
        deal: '',
        dealOptions: [],
        vipPackage: true,
        recommand: true,
        vipPackageFree: 'wipfree',
        cardinal: 1000,
        select: [
          {
            selected: 'low',
            options: [
              {
                label: '初级',
                value: 'low'
              }
            ]
          },
          {
            selected: '',
            options: []
          },
          {
            selected: '',
            options: []
          }
        ]
      },
      rules: {
        oldprice: [
          { required: true, message: '必填项', trigger: 'blur' },
          { validator: oldprice, trigger: 'blur' }
        ],
        newprice: [
          { required: true, message: '必填项', trigger: 'blur' },
          { validator: newprice, trigger: 'blur' }
        ],
        cardinal: [
          { required: true, message: '必填项', trigger: 'blur' },
          { type: 'number', message: '请填入正确基数', trigger: 'blur' }
        ]
      }
    }
  },
  computed: {
    min() {
      return this.form.original
    },
    assetsForm() {
      return this.assets
    }
  },
  methods: {
    nextStep() {
      this.$emit('goNext')
    },
    handleCancel() {
      this.$router.go(-1)
    },
    saveClass() {
      this.$router.push({ name: 'Merchant' })
    }
  }
}
</script>

<style lang="scss" scoped>
.package-basic {
  .lockclass {
    width: 100%;
    line-height: 40px;
    height: 40px !important;
    text-align: left;
    padding-left: 30px;
    background-color: #ebf4ff;
    margin-top: 30px;
  }
  .setclass {
    width: 100%;
    line-height: 40px;
    height: 40px !important;
    text-align: left;
    padding-left: 30px;
    background-color: #ebf4ff;
    margin-bottom: 30px;
  }
  .el-form {
    margin-top: 30px;
    .el-input {
      width: 200px;
    }
    .el-select {
      width: 130px;
    }
  }
}
</style>
